require 'chefspec'
require 'fauxhai'


describe '<%= @app.name %>::default' do

  before do
    Fauxhai.mock(platform: 'ubuntu', version: '12.04')
    Chef::Recipe.any_instance.stub(:search).with(:users, 'groups:sysadmin').and_return({name: 'tim', ssh_key:"asd"})  
  end

  let(:chef_run){
    # one could use :log_level => :debug,  as arg to _new_
    ChefSpec::ChefRunner.new.converge('<%= @app.name %>::default')
  }

  it 'should install the required packages' do
    packages = %w"apache nginx lighttpd"
    packages.each do |pkg|
      expect(chef_run).to install_package pkg
    end
    expect(chef_run).to install_gem_package "bundler"
  end

  it 'should create the application user' do
    expect(chef_run).to create_user "tim"
  end

end
